class Solution {
public:
    vector<int> dailyTemperatures(vector<int>& temperatures) {
        stack<int> S;
        stack<int> index;
        int sz=temperatures.size();
        vector<int> ans(sz,0);
        int prev=1,cur=0;
        for(int i=0;i<sz;i++)
        {
            while(!S.empty()&&temperatures[i]>S.top())
            {
                int days=i-index.top();
                ans[index.top()]=days;
                index.pop();
                S.pop();
            }
            S.push(temperatures[i]);
            index.push(i);
        }
        return ans;
    }
    
};
